class SceneManager {
	private _stage: egret.DisplayObjectContainer; //设置所有场景所在的舞台
	private mainScene: MainScene; //主场景
	private playerScene: PlayerScene; //玩家场景
	private heroScene: HeroScene; //英雄场景


	private constructor() {
		this.mainScene = new MainScene();
		this.playerScene = new PlayerScene();
		this.heroScene = new HeroScene();
	}
	/**
	 * 获取实例  单例模式
	 */
	static sceneManager: SceneManager;
	static get instance() {
		if (!this.sceneManager) {
			this.sceneManager = new SceneManager();
		}
		return this.sceneManager;
	}
	/**
	 * 设置根场景
	 */
	public setStage(stage: egret.DisplayObjectContainer) {
		this._stage = stage;
	}
	/**
	 * 主场景
	 */
	static toMainScene() {
		let stage: egret.DisplayObjectContainer = this.instance._stage; //根舞台
		let mainScene = this.instance.mainScene;

		// 取消所有底部按钮的选中状态
		setTimeout(function () {
			mainScene.toggleBtn(0);
		}, 0)
		// 判断主场景是否已经被添加
		if (!mainScene.parent) {
			stage.addChild(mainScene)
		}
		// 判断玩家场景是否在主场景中

		SceneManager.instance.playerScene.parent && mainScene.removeChild(SceneManager.instance.playerScene);
		SceneManager.instance.heroScene.parent && mainScene.removeChild(SceneManager.instance.heroScene);


	}
	/**
	 * 玩家场景
	 */
	static toPlayerScene() {
		let stage: egret.DisplayObjectContainer = this.instance._stage; //根舞台
		// 把玩家场景添加到主场景中
		this.instance.mainScene.addChild(this.instance.playerScene);
	}
	/**
	 * 英雄场景
	 */
	static toHeroScene() {
		let stage: egret.DisplayObjectContainer = this.instance._stage;
		this.instance.mainScene.addChild(this.instance.heroScene);
	}
	/**
	 * 场景toast
	 * param scene 要显示toast的场景  info 消息内容
	 */
	static showinfo(scene: eui.Component, info:string) {
		// 新建消息背景图
		let img: egret.Bitmap = new egret.Bitmap();
		img.texture = RES.getRes('toast-bg_png');
		scene.addChild(img);
		img.x = scene.width / 2 - img.width / 2
		img.y = 500
		img.height = 40
		// 新建label用来 展示消息
		let label:egret.TextField = new egret.TextField();
		label.text = info;
		
		scene.addChild(label);
		label.x = scene.width/2-label.width/2;
		label.y = 510;
		label.height = 40;

		// 定时器删除 img和label
		let timer:egret.Timer = new egret.Timer(1000,1);
		timer.start();
		timer.addEventListener(egret.TimerEvent.TIMER_COMPLETE,(e)=>{
			scene.removeChild(label);
			scene.removeChild(img);
		},this)
	}


}